# 字典类型
import json
from datetime import datetime

from sqlalchemy import func
from sqlalchemy.orm import aliased

from apps.model.baseModel import BaseModel
from apps.settingApi.api.lessees.model import lesseesModel
from comm.sqlalchemyConfig import db


class chartModel(db.Model):
    """
    看板
    """
    __tablename__ = 'tx_chart'
    id = db.Column(db.String(100), primary_key=True, autoincrement=False, doc='id')
    name = db.Column(db.String(125), nullable=False, doc='看板名称')
    type = db.Column(db.Integer, nullable=False, default=2, doc='看板类型', comment="1、系统模板；2、标准看板")
    config = db.Column(db.Text, nullable=True, default='', doc='配置')
    rem = db.Column(db.Text, nullable=True, default='', doc='备注')
    create_user = db.Column(db.String(50), nullable=True)
    create_time = db.Column(db.DateTime, default=datetime.now, nullable=True)
    update_user = db.Column(db.String(50), nullable=True)
    update_time = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now, nullable=True)
    lessees_id = db.Column(db.String(100), nullable=False, doc='归属租户')


class chartDataModel(db.Model):
    """
    看板
    """
    __tablename__ = 'tx_chart_data'
    id = db.Column(db.String(100), primary_key=True, autoincrement=False, doc='id')
    name = db.Column(db.String(125), nullable=False, doc='名称')
    componentName = db.Column(db.String(125), nullable=False, doc='组件模板',comment="panel:面板图;pie:饼形图;scrollTable:表格图;bar:柱形图;capsule:胶囊图")
    sql = db.Column(db.Text, nullable=False, default='', doc='数据集')
    pool = db.Column(db.String(125), nullable=False, doc='数据库连接池')
    rem = db.Column(db.Text, nullable=True, default='', doc='说明')
    create_user = db.Column(db.String(50), nullable=True)
    create_time = db.Column(db.DateTime, default=datetime.now, nullable=True)
    lessees_id = db.Column(db.String(100), nullable=False, doc='归属租户')

    @classmethod
    def superclassList(cls):
        dataList = [
            {
                "id": "panel",
                "label": "面板图",
                "children": []
            },
            {
                "id": "pie",
                "label": "饼形图",
                "children": []
            },
            {
                "id": "scrollTable",
                "label": "表格图",
                "children": []
            },
            {
                "id": "bar",
                "label": "柱形图",
                "children": []
            }, {
                "id": "capsule",
                "label": "胶囊图",
                "children": []
            }
        ]
        return dataList
